home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oh!X 2001 Spring
/
Oh!X 2001 Spring Special CD-ROM (Japan).7z
/
Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin
/
GALAXY
/
ohx5-1
/
render.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2001-01-10
|
3KB
|
116 lines
/*
Oh!X5号
GalaxyKnightsサンプル1
レンダリング部分
*/
/* ヘッダーインクルード */
#include "stdafx.h"
#include "ohx5_1.h"
int camera_pos_disp;
/*-------------------------------------------
アプリケーションの動作を一時停止する
--------------------------------------------*/
void pause_draw()
{
if (lpD3D) lpD3DD->Present(NULL,NULL,NULL,NULL); // GDIサーフェイスを表示する
DrawMenuBar( hwndApp ); // ウインドウのメニューバーを描画する
RedrawWindow(hwndApp, NULL, NULL, RDW_FRAME); // ウインドウのフレームを描画する
// while (ShowCursor(TRUE)<0) {}; // マウスカーソルを表示する
}
/*-------------------------------------------
停止していたアプリケーションの動作を再開する
--------------------------------------------*/
void restart_draw()
{
// while (ShowCursor(FALSE)>=0) {}; // マウスカーソルを消す
}
/*
実処理
*/
bool realtime_render(void)
{
HRESULT hr;
float scale;
OBJ3D *obp;
DWORD type,i,max;
D3DXMATRIX matRotate,matTranslate,mat,matX,matY,matZ,matView,matScaling;
D3DXVECTOR3 vec;
D3DXMatrixPerspectiveLH( &mat,1.0f,1.0f,1.0f,512.0f );
// カメラマトリックスを求める
D3DXMatrixRotationX( &matX,camera_rud.x );
D3DXMatrixRotationY( &matY,camera_rud.y );
D3DXMatrixRotationZ( &matZ,camera_rud.z );
matView = matY * matX * matZ;
lpD3DD->SetTransform( D3DTS_PROJECTION, &mat);
// Zバッファ&バックバッファ・クリア
lpD3DD->Clear( 0 ,NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,255),1.0f,0 );
// 描画の開始
lpD3DD ->BeginScene();
// lpD3DD->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// lpD3DD->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
// lpD3DD->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
obp = objtop;
while( obp !=NULL ){
if( obp->type==0 ){ obp = obp->next; continue; }
// スケーリング
scale = shapelist[obp->type].scale;
D3DXMatrixScaling( &matScaling,scale,scale,scale );
// ローカル回転マトリックスを求める
D3DXMatrixRotationX( &matX,-obp->rudder.x );
D3DXMatrixRotationY( &matY,-obp->rudder.y );
D3DXMatrixRotationZ( &matZ,-obp->rudder.z );
matRotate = matZ * matX * matY * matScaling;
// 中心座標をグローバル変換
vec = obp->pos - camera_pos;
D3DXVec3TransformNormal( &vec,&vec, &matView );
// 移動
D3DXMatrixTranslation(&matTranslate,
vec.x,
vec.y,
vec.z );
// 変換行列を計算
mat = matRotate * matView * matTranslate;
lpD3DD->SetTransform( D3DTS_WORLD, &mat);
type = shapelist[obp->type].type;
if( type==FILE_DATA ){
max = shapelist[obp->type].mats;
for( i=0;i<max;i++ ){
lpD3DD->SetMaterial( &shapelist[obp->type].lpmmats[i] );
lpD3DD->SetTexture( 0,shapelist[obp->type].lpmtexs[i] );
shapelist[obp->type].pt->DrawSubset( i );
}
} else {
shapelist[obp->type].pt->DrawSubset( 0 ); // 実際の描画
}
obp = obp->next;
}
lpD3DD->EndScene();
// フレーム更新、フリップだろうがブリットだろうがこれでOK
hr = lpD3DD->Present(NULL,NULL,NULL,NULL);
// if (hr == DDERR_SURFACELOST || hr == DDERR_SURFACEBUSY)
{
// サーフェイスが失われている場合の処理
// return restore_surface();
}
return SUCCEEDED(hr);
}